<?php
// Preset PHP settings
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(function_exists('date_default_timezone_set')) date_default_timezone_set('GMT');

// Define this as parent file
define('INDEX', 1);

// Define root directory
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__) . DS);

// Define folders directory
define('INCLUDES', ROOT . 'includes' . DS);
define('LANGUAGES', ROOT . 'languages' . DS);
define('LIBRARIES', ROOT . 'libraries' . DS);
define('LOGS', ROOT . 'logs' . DS);
define('PAGES', ROOT . 'pages' . DS);

// Include configuration file
require_once(ROOT . 'configuration.php');

// Import required functions and libraries
// Common functions
require_once(INCLUDES . 'functions.php');

// MySQL class
require_once(LIBRARIES . 'csv.class.php');

// Clean up all GET and POST values
if(isset($_GET)) foreach($_GET as $key=>$value) $_GET[$key] = stripslashes(trim($value));
if(isset($_POST)){
	foreach($_POST as $key=>$value){
		if(is_array($value)){
			foreach($value as $k=>$v){
				$value[$k] = stripslashes(trim($v));
			}
			$_POST[$key] = $value;
		}
		else{
			$_POST[$key] = stripslashes(trim($value));
		}
	}
}

// Get requested page
$q = isset($_GET['q']) ? $_GET['q'] : 'overview';

// Start session
if(session_id() == ''){
	// Generate an unique session Id
	$id = 0;
	while(strlen($id) < 32) $id .= mt_rand(0, mt_getrandmax());
	$id = md5(uniqid($id, true));

	// Start the session
	session_start();
}

// Load language file
include_once(INCLUDES . 'language.php');

// Display requested page
$showExtra = 0;
if(file_exists(PAGES . $q . '.php')){
	if($q != 'login') $showExtra = 1;
	include_once(PAGES . $q . '.php');
}
else include_once(PAGES . '404.php');
?>